package com.mao.utils;

import java.io.*;

/**
 * @Description:
 * @Param:
 * @Thought:
 * @Author: Wenjie Mao
 * @create： 2022-11-16 10:52
 */
@Deprecated
public class mergeJson {
    public static void main(String[] args) {
        mergeJson mergeJson = new mergeJson();
        mergeJson.mergeJson();
    }

    //传入json文件
    public void mergeJson() {
        FileInputStream inputStream = null;
        FileOutputStream outputStream = null;
        int index = 1;
        String url = "";
        try {
            //创建最终的res文件
            File file = new File("E:\\Android\\cloud-computing-nju2022\\java\\mao\\src\\json\\res.json");
            file.createNewFile();
            outputStream = new FileOutputStream(file);
            while (index <= 55) {
                //从文件夹中读取json文件
                System.out.println("reading page" + index + ".json from directory");
                url = "E:\\Android\\cloud-computing-nju2022\\java\\mao\\src\\json\\page" + index + ".json";
                inputStream = new FileInputStream(url);
                byte[] bytes = new byte[1024];
                //循环读入，同时写入
                System.out.println("writing into res.json");
                StringBuilder stringBuilder = new StringBuilder();

                while (true) {
                    int read = inputStream.read(bytes);
                    if (read != -1){
                        outputStream.write(bytes);
                        outputStream.flush();
                    }else{
                        break;
                    }
                }
                index++;
                System.out.println("page" + index + "completed");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                inputStream.close();
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
